package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.BranchDepartmentBean;
import com.itboye.jinpuyiyuan.bean.BranchDepartmentBeanNew;
import com.itboye.jinpuyiyuan.bean.GoodBean;
import com.itboye.jinpuyiyuan.bean.RegisterHospitalBean;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2017/12/9 0009.
 */

public class LeftAdapter extends BaseAdapter {

    private ArrayList<BranchDepartmentBeanNew.DepartmentChild> list;
    private Context context;
    private LayoutInflater inflater;
    private boolean isCancle=false;
    private int selectPosition;//选择的itemposition
    public  LeftAdapter(Context context,ArrayList<BranchDepartmentBeanNew.DepartmentChild>  list){

        this.list=list;
        this.context=context;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final RegisterHospitalHolder registerHospitalHolder;
        if (convertView==null){
            registerHospitalHolder=new RegisterHospitalHolder();
            convertView=inflater.inflate(R.layout.item_leftlist,parent,false);

            registerHospitalHolder.leftItemSelectImg=convertView.findViewById(R.id.leftItemSelectImg);
            registerHospitalHolder.leftItemSelectTv=convertView.findViewById(R.id.leftItemSelectTv);
            registerHospitalHolder.leftLL=convertView.findViewById(R.id.leftLL);
            convertView.setTag(registerHospitalHolder);
        }else {
            registerHospitalHolder= (RegisterHospitalHolder) convertView.getTag();
        }
        if (!isCancle) {
            if (position == 0) {
                registerHospitalHolder.leftItemSelectImg.setVisibility(View.VISIBLE);
                registerHospitalHolder.leftLL.setSelected(true);
                registerHospitalHolder.leftLL.setBackgroundColor(context.getResources().getColor(R.color.white));
            }
        }
        registerHospitalHolder.leftItemSelectTv.setText(list.get(position).getDept_name());
        registerHospitalHolder.leftLL.setSelected(false);
        registerHospitalHolder.leftLL.setBackgroundColor(context.getResources().getColor(R.color.app_gray));
        registerHospitalHolder.leftItemSelectImg.setVisibility(View.GONE);
        if (position==selectPosition){
            registerHospitalHolder.leftLL.setSelected(true);
            registerHospitalHolder.leftItemSelectImg.setVisibility(View.VISIBLE);
            registerHospitalHolder.leftLL.setBackgroundColor(context.getResources().getColor(R.color.white));
        }
        return convertView;
    }

    class RegisterHospitalHolder {
        TextView leftItemSelectTv;
        ImageView leftItemSelectImg;
        LinearLayout leftLL;

    }

    public void cancleAllItemState(int position1){
        isCancle=true;
        this.selectPosition=position1;
        this.notifyDataSetChanged();
    }

}
